class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        
        if(nums.size()<3){
            return 0;
        }
        int nRet=0;
        sort(nums.begin(),nums.end());
        for(int i=0;i<nums.size();++i){
            int left=0,right=i-1;
            while(left<right){
                if(nums[left]+nums[right]>nums[i]){
                    nRet+=right-left;
                    --right;
                }
                else{
                    ++left;
                }
            }
        }

        return nRet;
    }
};
